local skill = fk.CreateSkill {
  name = "bright__slash_skill",
}

Fk:loadTranslationTable{
  ["#bright_damage_skill-invoke"] = "你可以选择 %dest 两张手牌，明置其中暗置牌，弃置其中明置牌",
}

local DIY = require "packages/diy_utility/diy_utility"
local TT = require "packages/tuntian_studio/utility"
local slash_skill = Fk.skills["slash_skill"] --[[ @as ActiveSkill ]]

skill:addEffect("cardskill", {
  prompt = function(self, player, selected_cards)
    local card = Fk:cloneCard("bright__slash")
    card:addSubcards(selected_cards)
    local max_num = self:getMaxTargetNum(player, card)
    if max_num > 1 then
      local num = #table.filter(Fk:currentRoom().alive_players, function (p)
        return p ~= player and not player:isProhibited(p, card)
      end)
      max_num = math.min(num, max_num)
    end
    return max_num > 1 and "#bright__slash_skill_multi:::" .. max_num or "#bright__slash_skill"
  end,
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash_skill.canUse,
  mod_target_filter = slash_skill.modTargetFilter,
  target_filter = slash_skill.targetFilter,
  on_effect = function(self, room, effect)
    room:damage({
      from = effect.from,
      to = effect.to,
      card = effect.card,
      damage = 1,
      damageType = fk.BrightDamage,
      skillName = skill.name,
    })
  end,
})

skill:addEffect(fk.Damage, {
  global = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and data.damageType == fk.BrightDamage and
      data.card and data.card.name == "bright__slash" and data.to:isAlive() and
      not data.chain and not data.to:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = skill.name,
      prompt = "#bright_damage_skill-invoke::"..data.to.id,
    }) then
      event:setCostData(self, {tos = {data.to}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToChooseCards(player, {
      target = data.to,
      min = 1,
      max = 2,
      flag = "h",
      skill_name = skill.name,
    })
    local shown = table.filter(cards, function (id) return TT.isShown(id) end)
    local unshown = table.filter(cards, function (id) return not TT.isShown(id) end)
    if #shown > 0 then
      room:throwCard(shown, skill.name, data.to, player)
    end
    if #unshown > 0 then
      DIY.showCards(data.to, unshown)
    end
  end,
})

return skill
